home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 21 / Mac Magazin and MacEasy Magazine CD - Issue 21.iso / Wissenschaft & Technik / yorick12vr1-nofpu folder / include / testp.i < prev    next >
Text File  |  1996-02-29  |  50KB  |  1,788 lines

  1. /*
  2.    TESTP.I
  3.    Test of Yorick parser
  4.  
  5.    $Id: testp.i,v 1.1 1993/08/27 18:50:06 munro Exp munro $
  6.  */
  7. /*    Copyright (c) 1994.  The Regents of the University of California.
  8.                     All rights reserved.  */
  9.  
  10. goofs= 0;  /* cumulative tally of errors detected */
  11. write, "Begin Yorick parser test...";
  12. if (do_stats) "A "+print(yorick_stats());
  13.  
  14. /* ------------------------------------------------------------------------- */
  15.  
  16. /* First function is pure parser test, exercising many yucky language
  17.    features, but not producing any usable procedure.  Check disassembled
  18.    function to be sure code is correct.  */
  19. func parser_test(pos1, pos2, pos3, .., key1=, key2=, key3=)
  20. {
  21.   pos1= '\0';
  22.   pos2= 1s;
  23.   pos3= 2n;
  24.   loc1= 3L;
  25.   loc2= 4.0e0F;
  26.   loc3= 5.0;
  27.   loc4= 6.0i;
  28.   loc5= "A string with ' and /* inside.";
  29.  
  30.  
  31.   /* Blank lines, then a short comment with imbedded " character */
  32.  
  33.   /* A multiline comment with blank lines and various types of
  34.      quote characters,
  35.  
  36.      such as " and ',
  37.  
  38.  
  39.      all of which should be completely ignored... */
  40.  
  41. #if 0
  42. Try commenting something out with #if 0/#endif sequence
  43. #  if 0
  44.      These should nest properly...
  45. #  endif
  46. ...So this line should still be commented out.
  47. #endif
  48. #  if 0
  49.   Be sure indented style works.
  50. #  endif
  51.  
  52. // Comment out something with C++-style comment
  53.             // ... and another comment
  54. /*
  55. // Nested comment test
  56. terrible syntax error
  57. */
  58. //  first commented out line;  /* nested normal comment */
  59. //  second bad line;
  60. //   third bad line;
  61. //   fourth bad line;   /* final nested comment
  62.  
  63.   key1= pos3;   // C++ comment
  64.   /* initial comment */ key2 /* imbedded comment */ = 0 /* repeated
  65.      constant */ + 6.;  /* followed by a second repeated constant */
  66.  
  67.   key3= ext1;  /* first example of an external variable // nest test */
  68.  
  69.   local loc6;  local loc7, loc8, loc9;  // C++ style comment /* nesting */
  70.   extern ext2, ext3;  extern ext4;
  71.  
  72.   ext2= -1;  /* negative of existing constant */
  73.   loc6= - /* nasty imbedded
  74.          comment */ 7.0;
  75.  
  76.   ext3= "multiline string also tests escape sequences: \
  77. \\n\n, \\t\t, \\a\a, \\f\f, \\r\r, \\v\v, \\b\b, \', \"\n\
  78. \?, \q, C-a\1, C-b\02, C-c\003, C-d\0041 (should C-d1), C-z\x1A,\
  79. DEL\x7f";  /* Note: \? and \q should just give ? and q */
  80.  
  81.   loc7= ext4+1;
  82.   loc8= ext5();   /* should push nil argument */
  83.   ext5(pos1);
  84.   ext5(pos1, key1, loc1);
  85.   ext5(pos1, key1, .., loc1);
  86.   ext5;
  87.   ext5, pos1;
  88.   ext5, pos1, key1, loc1, ext1, /* final argument nil */;
  89.  
  90.   /* Try lines with implicit semi-colon terminators: */
  91.   loc7(3:, 6*loc1+loc2, ::loc2+loc3)=
  92.     5
  93.   loc8= loc7 + 7*
  94.     loc6(3,
  95.      )
  96.  
  97.   if (loc1) ext5
  98.   else ext5, 1
  99.  
  100.   if (loc1) ext5
  101.   ext5, 1
  102.  
  103.   /* Try several popular styles */
  104.   if (loc1) {
  105.     ext3;
  106.   } else if (!loc2) {
  107.     ext3, 1;
  108.   } else if (loc3) {
  109.     ext3, 1;
  110.     ext3, 2;
  111.   } else {
  112.     ext3, 3;
  113.   }
  114.  
  115.   if (loc1)
  116.   {
  117.     ext4;
  118.   }
  119.   else if (loc2)
  120.   {
  121.     ext4, 1;
  122.   }
  123.   else if (!loc3)
  124.   {
  125.     ext4, 1;
  126.     ext4, 2;
  127.   }
  128.   else
  129.   {
  130.     ext4, 3;
  131.   }
  132.  
  133.   if (!loc1) ext5;
  134.   else if (loc2) ext5, 1;
  135.   else if (loc3) { ext5, 1; ext5, 2; }
  136.   else ext5, 3;
  137.  
  138.   while (loc1--) {
  139.     ext6;
  140.     ext6, 2;
  141.   };            /* check that extraneous trailing semi-colon is OK */
  142.  
  143.  backward:
  144.   do {
  145.     ext6;
  146.     if (ext1) break;
  147.     if (ext2) continue;
  148.     ext6, 2;
  149.   } while (--loc1);
  150.  
  151.   if (ext6) goto forward;
  152.   if (ext3) goto backward;
  153.  
  154.   for (loc1=0 ; loc1<8 ; loc1++) {
  155.     ext5;
  156.     ext5, 2;
  157.   }
  158.  
  159.  forward:
  160.   for (loc1=0, loc2=loc3=0 ;
  161.        loc1<8 ;
  162.        loc1++, loc2+=2, loc3+=3) {
  163.     if (ext4>=9) continue;
  164.     ext5;
  165.     do {
  166.       ext6;
  167.       if (ext1!=3) break;
  168.       for (loc1=0 ; loc1<8 ; loc1++) {
  169.     ext5;
  170.     if (ext3<=2) break;
  171.     if (ext4==7) continue;
  172.     if (!ext1) goto inloop;
  173.     ext5, 2;
  174.       }
  175.       if (ext2) continue;
  176.       ext6, 2;
  177.     } while (--loc1);
  178.     if (ext3>3) break;
  179.     ext5, 2;
  180.   inloop:
  181.   }
  182.  
  183.   if (loc1 || loc2 && loc3) goto backward;
  184.  
  185.   return 3*loc1(3:12:3, ptp, avg:9:21)? 3+ext1 : 2-ext2;
  186. }
  187.  
  188. if (do_stats) "B "+print(yorick_stats());
  189.  
  190. #if 0
  191. Here is the correct disassemble output for parser_test:
  192. func parser_test(pos1,pos2,pos3,..,key1=,key2=,key3=)
  193.   17 sp->1    PushChar(0x00)
  194.   19 sp0>1    Define(pos1)
  195.   21 sp->0    DropTop
  196.   22 sp+>1    PushShort(1)
  197.   24 sp0>1    Define(pos2)
  198.   26 sp->0    DropTop
  199.   27 sp+>1    PushInt(2)
  200.   29 sp0>1    Define(pos3)
  201.   31 sp->0    DropTop
  202.   32 sp+>1    PushLong(3)
  203.   34 sp0>1    Define(loc1)
  204.   36 sp->0    DropTop
  205.   37 sp+>1    PushFloat(4)
  206.   39 sp0>1    Define(loc2)
  207.   41 sp->0    DropTop
  208.   42 sp+>1    PushDouble(5)
  209.   44 sp0>1    Define(loc3)
  210.   46 sp->0    DropTop
  211.   47 sp+>1    PushImaginary(6i)
  212.   49 sp0>1    Define(loc4)
  213.   51 sp->0    DropTop
  214.   52 sp+>1    PushString("A string with ' and /* i"...)
  215.   54 sp0>1    Define(loc5)
  216.   56 sp->0    DropTop
  217.   57 sp+>1    PushVariable(pos3)
  218.   59 sp0>1    Define(key1)
  219.   61 sp->0    DropTop
  220.   62 sp+>1    PushLong(0)
  221.   64 sp+>2    PushDouble(6)
  222.   66 sp->1    Add
  223.   67 sp0>1    Define(key2)
  224.   69 sp->0    DropTop
  225.   70 sp+>1    PushVariable(ext1)
  226.   72 sp0>1    Define(key3)
  227.   74 sp->0    DropTop
  228.   75 sp+>1    PushLong(-1)
  229.   77 sp0>1    Define(ext2)
  230.   79 sp->0    DropTop
  231.   80 sp+>1    PushDouble(-7)
  232.   82 sp0>1    Define(loc6)
  233.   84 sp->0    DropTop
  234.   85 sp+>1    PushString("multiline string also te"...)
  235.   87 sp0>1    Define(ext3)
  236.   89 sp->0    DropTop
  237.   90 sp+>1    PushVariable(ext4)
  238.   92 sp+>2    PushLong(1)
  239.   94 sp->1    Add
  240.   95 sp0>1    Define(loc7)
  241.   97 sp->0    DropTop
  242.   98 sp+>1    PushVariable(ext5)
  243.  100 sp+>2    PushNil
  244.  101 sp->1    Eval(1)
  245.  103 sp0>1    Define(loc8)
  246.  105 sp->0    DropTop
  247.  106 sp+>1    PushVariable(ext5)
  248.  108 sp+>2    PushReference(pos1)
  249.  110 sp->1    Eval(1)
  250.  112 sp0>1    Print
  251.  113 sp->0    DropTop
  252.  114 sp+>1    PushVariable(ext5)
  253.  116 sp+>2    PushReference(pos1)
  254.  118 sp+>3    PushReference(key1)
  255.  120 sp+>4    PushReference(loc1)
  256.  122 sp->1    Eval(3)
  257.  124 sp0>1    Print
  258.  125 sp->0    DropTop
  259.  126 sp+>1    PushVariable(ext5)
  260.  128 sp+>2    PushReference(pos1)
  261.  130 sp+>3    PushReference(key1)
  262.  132 sp+>4    FormRangeFlag(..)
  263.  134 sp+>5    PushReference(loc1)
  264.  136 sp->1    Eval(4)
  265.  138 sp0>1    Print
  266.  139 sp->0    DropTop
  267.  140 sp+>1    PushVariable(ext5)
  268.  142 sp0>1    Print
  269.  143 sp->0    DropTop
  270.  144 sp+>1    PushVariable(ext5)
  271.  146 sp+>2    PushReference(pos1)
  272.  148 sp->1    Eval(1)
  273.  150 sp->0    DropTop
  274.  151 sp+>1    PushVariable(ext5)
  275.  153 sp+>2    PushReference(pos1)
  276.  155 sp+>3    PushReference(key1)
  277.  157 sp+>4    PushReference(loc1)
  278.  159 sp+>5    PushReference(ext1)
  279.  161 sp+>6    PushNil
  280.  162 sp->1    Eval(5)
  281.  164 sp->0    DropTop
  282.  165 sp+>1    PushVariable(loc7)
  283.  167 sp+>2    PushLong(3)
  284.  169 sp+>3    PushNil
  285.  170 sp->2    FormRange(2)
  286.  172 sp+>3    PushLong(6)
  287.  174 sp+>4    PushVariable(loc1)
  288.  176 sp->3    Multiply
  289.  177 sp+>4    PushVariable(loc2)
  290.  179 sp->3    Add
  291.  180 sp+>4    PushNil
  292.  181 sp+>5    PushNil
  293.  182 sp+>6    PushVariable(loc2)
  294.  184 sp+>7    PushVariable(loc3)
  295.  186 sp->6    Add
  296.  187 sp->4    FormRange(3)
  297.  189 sp->1    Eval(3)
  298.  191 sp+>2    PushLong(5)
  299.  193 sp->1    Assign
  300.  194 sp->0    DropTop
  301.  195 sp+>1    PushVariable(loc7)
  302.  197 sp+>2    PushLong(7)
  303.  199 sp+>3    PushVariable(loc6)
  304.  201 sp+>4    PushLong(3)
  305.  203 sp+>5    PushNil
  306.  204 sp->3    Eval(2)
  307.  206 sp->2    Multiply
  308.  207 sp->1    Add
  309.  208 sp0>1    Define(loc8)
  310.  210 sp->0    DropTop
  311.  211 sp+>1    PushVariable(loc1)
  312.  213 sp->0    BranchFalse to pc= 221
  313.  215 sp+>1    PushVariable(ext5)
  314.  217 sp0>1    Print
  315.  218 sp->0    DropTop
  316.  219 sp0>0    Branch to pc= 228
  317.  221 sp+>1    PushVariable(ext5)
  318.  223 sp+>2    PushLong(1)
  319.  225 sp->1    Eval(1)
  320.  227 sp->0    DropTop
  321.  228 sp+>1    PushVariable(loc1)
  322.  230 sp->0    BranchFalse to pc= 236
  323.  232 sp+>1    PushVariable(ext5)
  324.  234 sp0>1    Print
  325.  235 sp->0    DropTop
  326.  236 sp+>1    PushVariable(ext5)
  327.  238 sp+>2    PushLong(1)
  328.  240 sp->1    Eval(1)
  329.  242 sp->0    DropTop
  330.  243 sp+>1    PushVariable(loc1)
  331.  245 sp->0    BranchFalse to pc= 253
  332.  247 sp+>1    PushVariable(ext3)
  333.  249 sp0>1    Print
  334.  250 sp->0    DropTop
  335.  251 sp0>0    Branch to pc= 293
  336.  253 sp+>1    PushVariable(loc2)
  337.  255 sp->0    BranchTrue to pc= 266
  338.  257 sp+>1    PushVariable(ext3)
  339.  259 sp+>2    PushLong(1)
  340.  261 sp->1    Eval(1)
  341.  263 sp->0    DropTop
  342.  264 sp0>0    Branch to pc= 293
  343.  266 sp+>1    PushVariable(loc3)
  344.  268 sp->0    BranchFalse to pc= 286
  345.  270 sp+>1    PushVariable(ext3)
  346.  272 sp+>2    PushLong(1)
  347.  274 sp->1    Eval(1)
  348.  276 sp->0    DropTop
  349.  277 sp+>1    PushVariable(ext3)
  350.  279 sp+>2    PushLong(2)
  351.  281 sp->1    Eval(1)
  352.  283 sp->0    DropTop
  353.  284 sp0>0    Branch to pc= 293
  354.  286 sp+>1    PushVariable(ext3)
  355.  288 sp+>2    PushLong(3)
  356.  290 sp->1    Eval(1)
  357.  292 sp->0    DropTop
  358.  293 sp+>1    PushVariable(loc1)
  359.  295 sp->0    BranchFalse to pc= 303
  360.  297 sp+>1    PushVariable(ext4)
  361.  299 sp0>1    Print
  362.  300 sp->0    DropTop
  363.  301 sp0>0    Branch to pc= 343
  364.  303 sp+>1    PushVariable(loc2)
  365.  305 sp->0    BranchFalse to pc= 316
  366.  307 sp+>1    PushVariable(ext4)
  367.  309 sp+>2    PushLong(1)
  368.  311 sp->1    Eval(1)
  369.  313 sp->0    DropTop
  370.  314 sp0>0    Branch to pc= 343
  371.  316 sp+>1    PushVariable(loc3)
  372.  318 sp->0    BranchTrue to pc= 336
  373.  320 sp+>1    PushVariable(ext4)
  374.  322 sp+>2    PushLong(1)
  375.  324 sp->1    Eval(1)
  376.  326 sp->0    DropTop
  377.  327 sp+>1    PushVariable(ext4)
  378.  329 sp+>2    PushLong(2)
  379.  331 sp->1    Eval(1)
  380.  333 sp->0    DropTop
  381.  334 sp0>0    Branch to pc= 343
  382.  336 sp+>1    PushVariable(ext4)
  383.  338 sp+>2    PushLong(3)
  384.  340 sp->1    Eval(1)
  385.  342 sp->0    DropTop
  386.  343 sp+>1    PushVariable(loc1)
  387.  345 sp->0    BranchTrue to pc= 353
  388.  347 sp+>1    PushVariable(ext5)
  389.  349 sp0>1    Print
  390.  350 sp->0    DropTop
  391.  351 sp0>0    Branch to pc= 393
  392.  353 sp+>1    PushVariable(loc2)
  393.  355 sp->0    BranchFalse to pc= 366
  394.  357 sp+>1    PushVariable(ext5)
  395.  359 sp+>2    PushLong(1)
  396.  361 sp->1    Eval(1)
  397.  363 sp->0    DropTop
  398.  364 sp0>0    Branch to pc= 393
  399.  366 sp+>1    PushVariable(loc3)
  400.  368 sp->0    BranchFalse to pc= 386
  401.  370 sp+>1    PushVariable(ext5)
  402.  372 sp+>2    PushLong(1)
  403.  374 sp->1    Eval(1)
  404.  376 sp->0    DropTop
  405.  377 sp+>1    PushVariable(ext5)
  406.  379 sp+>2    PushLong(2)
  407.  381 sp->1    Eval(1)
  408.  383 sp->0    DropTop
  409.  384 sp0>0    Branch to pc= 393
  410.  386 sp+>1    PushVariable(ext5)
  411.  388 sp+>2    PushLong(3)
  412.  390 sp->1    Eval(1)
  413.  392 sp->0    DropTop
  414.  393 sp+>1    PushVariable(loc1)
  415.  395 sp+>2    Push1
  416.  396 sp+>3    DupUnder
  417.  397 sp->2    Subtract
  418.  398 sp0>2    Define(loc1)
  419.  400 sp->1    DropTop
  420.  401 sp->0    BranchFalse to pc= 416
  421.  403 sp+>1    PushVariable(ext6)
  422.  405 sp0>1    Print
  423.  406 sp->0    DropTop
  424.  407 sp+>1    PushVariable(ext6)
  425.  409 sp+>2    PushLong(2)
  426.  411 sp->1    Eval(1)
  427.  413 sp->0    DropTop
  428.  414 sp0>0    Branch to pc= 393
  429.  416 sp+>1    PushVariable(ext6)
  430.  418 sp0>1    Print
  431.  419 sp->0    DropTop
  432.  420 sp+>1    PushVariable(ext1)
  433.  422 sp->0    BranchFalse to pc= 426
  434.  424 sp0>0    Branch to pc= 447
  435.  426 sp+>1    PushVariable(ext2)
  436.  428 sp->0    BranchFalse to pc= 432
  437.  430 sp0>0    Branch to pc= 439
  438.  432 sp+>1    PushVariable(ext6)
  439.  434 sp+>2    PushLong(2)
  440.  436 sp->1    Eval(1)
  441.  438 sp->0    DropTop
  442.  439 sp+>1    PushVariable(loc1)
  443.  441 sp+>2    Push1
  444.  442 sp->1    Subtract
  445.  443 sp0>1    Define(loc1)
  446.  445 sp->0    BranchTrue to pc= 416
  447.  447 sp+>1    PushVariable(ext6)
  448.  449 sp->0    BranchFalse to pc= 453
  449.  451 sp0>0    Branch to pc= 493
  450.  453 sp+>1    PushVariable(ext3)
  451.  455 sp->0    BranchFalse to pc= 459
  452.  457 sp0>0    Branch to pc= 416
  453.  459 sp+>1    PushLong(0)
  454.  461 sp0>1    Define(loc1)
  455.  463 sp->0    DropTop
  456.  464 sp+>1    PushVariable(loc1)
  457.  466 sp+>2    PushLong(8)
  458.  468 sp->1    Less
  459.  469 sp->0    BranchFalse to pc= 493
  460.  471 sp+>1    PushVariable(ext5)
  461.  473 sp0>1    Print
  462.  474 sp->0    DropTop
  463.  475 sp+>1    PushVariable(ext5)
  464.  477 sp+>2    PushLong(2)
  465.  479 sp->1    Eval(1)
  466.  481 sp->0    DropTop
  467.  482 sp+>1    PushVariable(loc1)
  468.  484 sp+>2    Push1
  469.  485 sp+>3    DupUnder
  470.  486 sp->2    Add
  471.  487 sp0>2    Define(loc1)
  472.  489 sp->1    DropTop
  473.  490 sp->0    DropTop
  474.  491 sp0>0    Branch to pc= 464
  475.  493 sp+>1    PushLong(0)
  476.  495 sp0>1    Define(loc1)
  477.  497 sp->0    DropTop
  478.  498 sp+>1    PushLong(0)
  479.  500 sp0>1    Define(loc3)
  480.  502 sp0>1    Define(loc2)
  481.  504 sp->0    DropTop
  482.  505 sp+>1    PushVariable(loc1)
  483.  507 sp+>2    PushLong(8)
  484.  509 sp->1    Less
  485.  510 sp->0    BranchFalse to pc= 660
  486.  512 sp+>1    PushVariable(ext4)
  487.  514 sp+>2    PushLong(9)
  488.  516 sp->1    GreaterEQ
  489.  517 sp->0    BranchFalse to pc= 521
  490.  519 sp0>0    Branch to pc= 633
  491.  521 sp+>1    PushVariable(ext5)
  492.  523 sp0>1    Print
  493.  524 sp->0    DropTop
  494.  525 sp+>1    PushVariable(ext6)
  495.  527 sp0>1    Print
  496.  528 sp->0    DropTop
  497.  529 sp+>1    PushVariable(ext1)
  498.  531 sp+>2    PushLong(3)
  499.  533 sp->1    NotEqual
  500.  534 sp->0    BranchFalse to pc= 538
  501.  536 sp0>0    Branch to pc= 617
  502.  538 sp+>1    PushLong(0)
  503.  540 sp0>1    Define(loc1)
  504.  542 sp->0    DropTop
  505.  543 sp+>1    PushVariable(loc1)
  506.  545 sp+>2    PushLong(8)
  507.  547 sp->1    Less
  508.  548 sp->0    BranchFalse to pc= 596
  509.  550 sp+>1    PushVariable(ext5)
  510.  552 sp0>1    Print
  511.  553 sp->0    DropTop
  512.  554 sp+>1    PushVariable(ext3)
  513.  556 sp+>2    PushLong(2)
  514.  558 sp->1    LessEQ
  515.  559 sp->0    BranchFalse to pc= 563
  516.  561 sp0>0    Branch to pc= 596
  517.  563 sp+>1    PushVariable(ext4)
  518.  565 sp+>2    PushLong(7)
  519.  567 sp->1    Equal
  520.  568 sp->0    BranchFalse to pc= 572
  521.  570 sp0>0    Branch to pc= 585
  522.  572 sp+>1    PushVariable(ext1)
  523.  574 sp->0    BranchTrue to pc= 578
  524.  576 sp0>0    Branch to pc= 633
  525.  578 sp+>1    PushVariable(ext5)
  526.  580 sp+>2    PushLong(2)
  527.  582 sp->1    Eval(1)
  528.  584 sp->0    DropTop
  529.  585 sp+>1    PushVariable(loc1)
  530.  587 sp+>2    Push1
  531.  588 sp+>3    DupUnder
  532.  589 sp->2    Add
  533.  590 sp0>2    Define(loc1)
  534.  592 sp->1    DropTop
  535.  593 sp->0    DropTop
  536.  594 sp0>0    Branch to pc= 543
  537.  596 sp+>1    PushVariable(ext2)
  538.  598 sp->0    BranchFalse to pc= 602
  539.  600 sp0>0    Branch to pc= 609
  540.  602 sp+>1    PushVariable(ext6)
  541.  604 sp+>2    PushLong(2)
  542.  606 sp->1    Eval(1)
  543.  608 sp->0    DropTop
  544.  609 sp+>1    PushVariable(loc1)
  545.  611 sp+>2    Push1
  546.  612 sp->1    Subtract
  547.  613 sp0>1    Define(loc1)
  548.  615 sp->0    BranchTrue to pc= 525
  549.  617 sp+>1    PushVariable(ext3)
  550.  619 sp+>2    PushLong(3)
  551.  621 sp->1    Greater
  552.  622 sp->0    BranchFalse to pc= 626
  553.  624 sp0>0    Branch to pc= 660
  554.  626 sp+>1    PushVariable(ext5)
  555.  628 sp+>2    PushLong(2)
  556.  630 sp->1    Eval(1)
  557.  632 sp->0    DropTop
  558.  633 sp+>1    PushVariable(loc1)
  559.  635 sp+>2    Push1
  560.  636 sp+>3    DupUnder
  561.  637 sp->2    Add
  562.  638 sp0>2    Define(loc1)
  563.  640 sp->1    DropTop
  564.  641 sp->0    DropTop
  565.  642 sp+>1    PushVariable(loc2)
  566.  644 sp+>2    PushLong(2)
  567.  646 sp->1    Add
  568.  647 sp0>1    Define(loc2)
  569.  649 sp->0    DropTop
  570.  650 sp+>1    PushVariable(loc3)
  571.  652 sp+>2    PushLong(3)
  572.  654 sp->1    Add
  573.  655 sp0>1    Define(loc3)
  574.  657 sp->0    DropTop
  575.  658 sp0>0    Branch to pc= 505
  576.  660 sp+>1    PushVariable(loc1)
  577.  662 sp->0    BranchTrue to pc= 673
  578.  664 sp+>1    PushVariable(loc2)
  579.  666 sp->0    BranchFalse to pc= 671
  580.  668 sp+>1    PushVariable(loc3)
  581.  670 sp==0    AndOrLogical for &&
  582.  671 sp+>1    Push0
  583.  672 sp==0    AndOrLogical for ||
  584.  673 sp+>1    Push1
  585.  674 sp->0    BranchFalse to pc= 678
  586.  676 sp0>0    Branch to pc= 416
  587.  678 sp+>1    PushLong(3)
  588.  680 sp+>2    PushVariable(loc1)
  589.  682 sp+>3    PushLong(3)
  590.  684 sp+>4    PushLong(12)
  591.  686 sp+>5    PushLong(3)
  592.  688 sp->3    FormRange(3)
  593.  690 sp+>4    FormRangeFunc(ptp:)
  594.  692 sp+>5    PushLong(9)
  595.  694 sp+>6    PushLong(21)
  596.  696 sp->5    FormRange(2)
  597.  698 sp0>5    AddRangeFunc(avg:)
  598.  700 sp->2    Eval(3)
  599.  702 sp->1    Multiply
  600.  703 sp->0    BranchFalse to pc= 712
  601.  705 sp+>1    PushLong(3)
  602.  707 sp+>2    PushVariable(ext1)
  603.  709 sp->1    Add
  604.  710 sp0>1    Branch to pc= 717
  605.  712 sp+>1    PushLong(2)
  606.  714 sp+>2    PushVariable(ext2)
  607.  716 sp->1    Subtract
  608.  717 sp->0    Return
  609.  718 sp==0    Halt-Virtual-Machine
  610. #endif
  611.  
  612. /* Try reinstated line */
  613. junk= 1;
  614. #if 1
  615. junk= 0;
  616. #  if 0
  617. junk= 2;
  618. #  endif
  619. #endif
  620. if (junk) {
  621.   goofs++;
  622.   "**FAILURE** #if / #endif construction broken";
  623. }
  624.  
  625. /* ------------------------------------------------------------------------- */
  626.  
  627. f= open("./include/testp.i", "r", 1);
  628. if (f) {
  629.   while (!strmatch((line= rdline(f)), "Here is the correct disassemble"));
  630.   correct= [];
  631.   while (!strmatch((line= rdline(f)), "#endif")) grow, correct, line;
  632.   close, f;
  633.   if (anyof(disassemble(parser_test)!=correct)) {
  634.     goofs++;
  635.     "**FAILURE** of the parser_test disassembly";
  636.     "            -- writing disassmbly of parser_test to pjunk.jnk";
  637.     f= open("pjunk.jnk", "w");
  638.     write, f, format="%s\n", disassemble(parser_test);
  639.     close, f;
  640.   }
  641.   correct= [];
  642. } else {
  643.   "WARNING-- skipping disassembly check, include/testp.i not present";
  644. }
  645. parser_test= [];
  646.  
  647. /* Check for limitation on yacc-parser stack depth.
  648.    If this fails with a SYNTAX error like "yacc stack overflow", see
  649.    top of yorick.y source-- your yacc may have a switch to fix it.  */
  650. { if (1) x= [1, 2];
  651.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  652.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  653.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  654.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  655.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  656.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  657.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  658.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  659.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  660.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  661.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  662.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  663.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  664.   else if (1) x= [1, 2]; else if (1) x= [1, 2]; else if (1) x= [1, 2];
  665.   else x= [1,2]; }
  666.  
  667. x= [];
  668.  
  669. if (do_stats) "C "+print(yorick_stats());
  670.  
  671. /* ------------------------------------------------------------------------- */
  672.  
  673. write, "Test 17x10x10 binary operators...";
  674.  
  675. /* Test all binary operations.  There are 10 data types and
  676.    17 operators, so the complete test involves 1700 function calls... */
  677. iS= 1n;  lS= 1;  dS= 1.0
  678. cA= ['\1', '\2'];  sA= [1s, 2s];  iA= [1n, 2n];  lA= [1, 2];
  679. fA= [1.0f, 2.0f];  dA= [1., 2.];  zA= [1+0i, 2+0i];
  680.  
  681. func op_test(SS, AS, SA, AA, op_name) /* SS, .. AA are correct answers */
  682. {
  683.   extern op;               /* the function to be tested */
  684.   goof= array(1, 10, 10);  /* array to hold any mistakes */
  685.  
  686.   except_complex= only_integer= goof;
  687.   except_complex(10,)= except_complex(,10)= 0;
  688.   only_integer(3,)= only_integer(,3)= 0;
  689.   only_integer(8:,)= 0;  only_integer(,8:)= 0;
  690.  
  691.   answer= SS;
  692.   op,iS,iS,1,1; op,lS,iS,2,1; op,dS,iS,3,1;
  693.   op,iS,lS,1,2; op,lS,lS,2,2; op,dS,lS,3,2;
  694.   op,iS,dS,1,3; op,lS,dS,2,3; op,dS,dS,3,3;
  695.  
  696.   answer= AS;
  697.   op,cA,iS,4,1; op,sA,iS,5,1; op,iA,iS,6,1; op,lA,iS,7,1;
  698.   op,fA,iS,8,1; op,dA,iS,9,1; op,zA,iS,10,1;
  699.   op,cA,lS,4,2; op,sA,lS,5,2; op,iA,lS,6,2; op,lA,lS,7,2;
  700.   op,fA,lS,8,2; op,dA,lS,9,2; op,zA,lS,10,2;
  701.   op,cA,dS,4,3; op,sA,dS,5,3; op,iA,dS,6,3; op,lA,dS,7,3;
  702.   op,fA,dS,8,3; op,dA,dS,9,3; op,zA,dS,10,3;
  703.  
  704.   answer= SA;
  705.   op,iS,cA,1,4; op,iS,sA,1,5; op,iS,iA,1,6; op,iS,lA,1,7;
  706.   op,iS,fA,1,8; op,iS,dA,1,9; op,iS,zA,1,10;
  707.   op,lS,cA,2,4; op,lS,sA,2,5; op,lS,iA,2,6; op,lS,lA,2,7;
  708.   op,lS,fA,2,8; op,lS,dA,2,9; op,lS,zA,2,10;
  709.   op,dS,cA,3,4; op,dS,sA,3,5; op,dS,iA,3,6; op,dS,lA,3,7;
  710.   op,dS,fA,3,8; op,dS,dA,3,9; op,dS,zA,3,10;
  711.  
  712.   answer= AA;
  713.   op,cA,cA,4,4; op,cA,sA,4,5; op,cA,iA,4,6; op,cA,lA,4,7;
  714.   op,cA,fA,4,8; op,cA,dA,4,9; op,cA,zA,4,10;
  715.   op,sA,cA,5,4; op,sA,sA,5,5; op,sA,iA,5,6; op,sA,lA,5,7;
  716.   op,sA,fA,5,8; op,sA,dA,5,9; op,sA,zA,5,10;
  717.   op,iA,cA,6,4; op,iA,sA,6,5; op,iA,iA,6,6; op,iA,lA,6,7;
  718.   op,iA,fA,6,8; op,iA,dA,6,9; op,iA,zA,6,10;
  719.   op,lA,cA,7,4; op,lA,sA,7,5; op,lA,iA,7,6; op,lA,lA,7,7;
  720.   op,lA,fA,7,8; op,lA,dA,7,9; op,lA,zA,7,10;
  721.   op,fA,cA,8,4; op,fA,sA,8,5; op,fA,iA,8,6; op,fA,lA,8,7;
  722.   op,fA,fA,8,8; op,fA,dA,8,9; op,fA,zA,8,10;
  723.   op,dA,cA,9,4; op,dA,sA,9,5; op,dA,iA,9,6; op,dA,lA,9,7;
  724.   op,dA,fA,9,8; op,dA,dA,9,9; op,dA,zA,9,10;
  725.   op,zA,cA,10,4; op,zA,sA,10,5; op,zA,iA,10,6; op,zA,lA,10,7;
  726.   op,zA,fA,10,8; op,zA,dA,10,9; op,zA,zA,10,10;
  727.  
  728.   if (anyof(goof)) {
  729.     goofs++;
  730.     "**FAILURE** of the following operations "+op_name+":";
  731.     where2(goof);
  732.   }
  733. }
  734.  
  735. if (do_stats) "D "+print(yorick_stats());
  736.  
  737. func op(l, r, il, ir)
  738. { goof(il, ir)= anyof((l + r)!=answer); }
  739. op_test, 2, [2, 3], [2, 3], [2, 4], "+";
  740.  
  741. func op(l, r, il, ir)
  742. { goof(il, ir)= anyof((l - r)!=answer); }
  743. op_test, 0, [0, 1], [0, -1], [0, 0], "-";
  744.  
  745. func op(l, r, il, ir)
  746. { goof(il, ir)= anyof((l * r)!=answer); }
  747. op_test, 1, [1, 2], [1, 2], [1, 4], "*";
  748.  
  749. func op(l, r, il, ir)
  750. {
  751.   if (structof(l+r)!=structof(l+r+0.0f))
  752.     goof(il, ir)= anyof((l / r)!=structof(l+r)(answer));
  753.   else /* otherwise fails on Crays because division is inexact */
  754.     goof(il, ir)= anyof(abs((l / r) - answer) > 1.e-6);
  755. }
  756. op_test, 1, [1, 2], [1, 0.5], [1, 1], "/";
  757.  
  758. func op(l, r, il, ir)
  759. {
  760.   if (structof(r)!=structof(r+0.0f))
  761.     goof(il, ir)= anyof((l ^ r)!=answer);
  762.   else /* otherwise fails on MacIntosh for unknown reason */
  763.     goof(il, ir)= anyof(abs((l ^ r) - answer) > 1.e-6);
  764. }
  765. op_test, 1, [1, 2], [1, 1], [1, 4], "^";
  766.  
  767. func op(l, r, il, ir)
  768. { goof(il, ir)= anyof((l == r)!=answer); }
  769. op_test, 1, [1, 0], [1, 0], [1, 1], "==";
  770.  
  771. func op(l, r, il, ir)
  772. { goof(il, ir)= anyof((l != r)!=answer); }
  773. op_test, 0, [0, 1], [0, 1], [0, 0], "!=";
  774.  
  775. func op(l, r, il, ir)
  776. { goof(il, ir)= except_complex(il, ir) && anyof((l % r)!=answer); }
  777. op_test, 0, [0, 0], [0, 1], [0, 0], "%";
  778.  
  779. func op(l, r, il, ir)
  780. { goof(il, ir)= except_complex(il, ir) && anyof((l > r)!=answer); }
  781. op_test, 0, [0, 1], [0, 0], [0, 0], ">";
  782.  
  783. func op(l, r, il, ir)
  784. { goof(il, ir)= except_complex(il, ir) && anyof((l <= r)!=answer); }
  785. op_test, 1, [1, 0], [1, 1], [1, 1], "<=";
  786.  
  787. func op(l, r, il, ir)
  788. { goof(il, ir)= except_complex(il, ir) && anyof((l < r)!=answer); }
  789. op_test, 0, [0, 0], [0, 1], [0, 0], "<";
  790.  
  791. func op(l, r, il, ir)
  792. { goof(il, ir)= except_complex(il, ir) && anyof((l >= r)!=answer); }
  793. op_test, 1, [1, 1], [1, 0], [1, 1], ">=";
  794.  
  795. func op(l, r, il, ir)
  796. { goof(il, ir)= only_integer(il, ir) && anyof((l << r)!=answer); }
  797. op_test, 2, [2, 4], [2, 4], [2, 8], "<<";
  798.  
  799. func op(l, r, il, ir)
  800. { goof(il, ir)= only_integer(il, ir) && anyof((l >> r)!=answer); }
  801. op_test, 0, [0, 1], [0, 0], [0, 0], ">>";
  802.  
  803. func op(l, r, il, ir)
  804. { goof(il, ir)= only_integer(il, ir) && anyof((l & r)!=answer); }
  805. op_test, 1, [1, 0], [1, 0], [1, 2], "&";
  806.  
  807. func op(l, r, il, ir)
  808. { goof(il, ir)= only_integer(il, ir) && anyof((l | r)!=answer); }
  809. op_test, 1, [1, 3], [1, 3], [1, 2], "|";
  810.  
  811. func op(l, r, il, ir)
  812. { goof(il, ir)= only_integer(il, ir) && anyof((l ~ r)!=answer); }
  813. op_test, 0, [0, 3], [0, 3], [0, 0], "~";
  814.  
  815. op= op_test= [];
  816. if (do_stats) "E "+print(yorick_stats());
  817.  
  818. /* ------------------------------------------------------------------------- */
  819.  
  820. write, "Test unary operators...";
  821.  
  822. /* Test all unary operators. */
  823.  
  824. func op_test(SS, AA, op_name) /* SS, AA are correct answers */
  825. {
  826.   extern op;               /* the function to be tested */
  827.   goof= array(1, 10);      /* array to hold any mistakes */
  828.  
  829.   except_complex= only_integer= goof;
  830.   except_complex(10)= 0;
  831.   only_integer(3)= 0;
  832.   only_integer(8:)= 0;
  833.  
  834.   answer= SS;
  835.   op,iS,1; op,lS,2; op,dS,3;
  836.  
  837.   answer= AA&0xff;
  838.   op,cA,4;
  839.   answer= AA;
  840.   op,sA,5; op,iA,6; op,lA,7; op,fA,8; op,dA,9; op,zA,10;
  841.  
  842.   if (anyof(goof)) {
  843.     goofs++;
  844.     "**FAILURE** of the following operations "+op_name+":";
  845.     where2(goof);
  846.   }
  847. }
  848.  
  849. if (do_stats) "F "+print(yorick_stats());
  850.  
  851. func op(l, il)
  852. { goof(il)= anyof((+ l)!=answer); }
  853. op_test, 1, [1, 2], "+";
  854.  
  855. func op(l, il)
  856. { goof(il)= anyof((- l)!=answer); }
  857. op_test, -1, [-1, -2], "-";
  858.  
  859. func op(l, il)
  860. { goof(il)= anyof((! (l-1))!=answer); }
  861. op_test, 1, [1, 0], "!";
  862.  
  863. func op(l, il)
  864. { goof(il)= only_integer(il) && anyof((~ l)!=answer); }
  865. op_test, -2, [-2, -3], "~";
  866.  
  867. op= op_test= [];
  868. if (do_stats) "G "+print(yorick_stats());
  869.  
  870. /* ------------------------------------------------------------------------- */
  871.  
  872. write, "Test array manipulation functions...";
  873.  
  874. /* Test array manipulation functions. */
  875.  
  876. func not_near(x,y)
  877. {
  878.   return anyof(abs(x-y)>1.e-9);
  879. }
  880.  
  881. x= [0,1](-,) + [0,10,20](-,-,) + [0,100,200,300](-,-,-,) +
  882.    [0,1000,2000,3000,4000](-,-,-,-,) +
  883.    [0,10000,20000,30000,40000,50000](-,-,-,-,-,);
  884. if (x(1,2,3,4,5,6)!=54321 || x(1,2,1,1,3,4)!=32001) {
  885.   goofs++;
  886.   "**FAILURE** of - subscript or broadcasting";
  887. }
  888.  
  889. y= [];
  890. grow, y, -2;
  891. if (anyof(y!=-2)) { 
  892.   goofs++;
  893.   "**FAILURE** of grow test 1";
  894. }
  895. grow, y, [1,2,3];
  896. if (anyof(y!=[-2,1,2,3])) { 
  897.   goofs++;
  898.   "**FAILURE** of grow test 2";
  899. }
  900. grow, y, [6,5,4];
  901. if (anyof(y!=[-2,1,2,3,6,5,4])) { 
  902.   goofs++;
  903.   "**FAILURE** of grow test 3";
  904. }
  905. y= [[1,2,3],[4,5,6]];
  906. grow, y, -1;
  907. if (anyof(y!=[[1,2,3],[4,5,6],[-1,-1,-1]])) { 
  908.   goofs++;
  909.   "**FAILURE** of grow test 4";
  910. }
  911. grow, y, [6,5,4];
  912. if (anyof(y!=[[1,2,3],[4,5,6],[-1,-1,-1],[6,5,4]])) { 
  913.   goofs++;
  914.   "**FAILURE** of grow test 5";
  915. }
  916.  
  917. if (indgen(0)!=orgsof([1])(1) ||
  918.     anyof(indgen(5)!=[0,1,2,3,4]+indgen(0))) {
  919.   goofs++;
  920.   "**FAILURE** of indgen function";
  921. }
  922.  
  923. if (not_near(span(1,4,4), [1,2,3,4]) ||
  924.     not_near(span(0,[2,4],3), [[0,1,2],[0,2,4]]) ||
  925.     not_near(span(0,[2,4],3,0), [[0,0],[1,2],[2,4]]) ||
  926.     not_near(spanl(1,8,4), [1,2,4,8]) ||
  927.     not_near(spanl(1,[4,16],3,0), [[1,1],[2,4],[4,16]])) {
  928.   goofs++;
  929.   "**FAILURE** of span or spanl function";
  930. }
  931.  
  932. y= [0., 1, 2, 3, 4, 5, 6, 7, 8, 9];
  933. if (digitize(3.5, y)!=5 ||
  934.     anyof(digitize([[-5, 8.5],[11,5],[.5,-.5]],y)!=[[1,10],[11,7],[2,1]]) ||
  935.     anyof(digitize([[-5, 8.5],[11,5],[.5,-.5]],y(::-1))!=
  936.       [[11,2],[1,5],[10,11]])) {
  937.   goofs++;
  938.   "**FAILURE** of digitize function";
  939. }
  940.  
  941. if (interp(y, y, 3.5)!=3.5 ||
  942.     anyof(interp(y,y,[[-5, 8.5],[11,5],[.5,-.5]])!=[[0,8.5],[9,5],[.5,0]]) ||
  943.     anyof(interp([y,y],y,[[-5, 8.5],[11,5],[.5,-.5]])!=
  944.       [[[0,8.5],[9,5],[.5,0]],[[0,8.5],[9,5],[.5,0]]]) ||
  945.     anyof(interp(transpose([y,y]),y,[[-5, 8.5],[11,5],[.5,-.5]],0)!=
  946.       [[[0,0],[8.5,8.5]],[[9,9],[5,5]],[[.5,.5],[0,0]]])) {
  947.   goofs++;
  948.   "**FAILURE** of interp function";
  949. }
  950.  
  951. if (not_near(integ(y, y, 3.5), 0.5*3.5^2) ||
  952.     not_near(integ(y,y,[[-5, 8.5],[11,5],[.5,-.5]]),
  953.          0.5*[[0,8.5],[9,5],[.5,0]]^2)) {
  954.   goofs++;
  955.   "**FAILURE** of integ function";
  956. }
  957.  
  958. if (anyof(histogram([1,5,2,1,1,5,2,1,4,5])!=[4,2,0,1,3]) ||
  959.     anyof(histogram([1,5,2,1,1,5,2,1,4,5],top=7)!=[4,2,0,1,3,0,0]) ||
  960.     anyof(histogram([1,5,2,1,1,5,2,1,4,5],y,top=7)!=
  961.       [14.,8.,0.,8.,15.,0.,0.])) {
  962.   goofs++;
  963.   "**FAILURE** of histogram function";
  964. }
  965.  
  966. if (anyof(poly([0.,1.,2.], 1,-2,1)!=[1.,0.,1.]) ||
  967.     anyof(poly([0.,1.,2.], 1,[-2,-1,0],1)!=[1.,1.,5.])) {
  968.   goofs++;
  969.   "**FAILURE** of poly function";
  970. }
  971.  
  972. if (anyof(sort([5,1,7,3])!=[2,4,1,3]) ||
  973.     anyof(sort([5.,1.,7.,3.])!=[2,4,1,3]) ||
  974.     anyof(sort(["go", "a", "stay", "abc"])!=[2,4,1,3]) ||
  975.     median([5.,1.,7.,3.])!=4 || median([5.,1.,7.,3.,-2500.])!=3 ||
  976.     anyof(median([[5.,1.,7.,3.],[5.,1.,99.,3.]])!=[4,4]) ||
  977.     anyof(median([[5.,5.],[-55.,1.],[7.,99.],[3.,3.]],0)!=[4,4])) {
  978.   goofs++;
  979.   "**FAILURE** of sort or median function";
  980. }
  981.  
  982. if (anyof(dimsof(x)                          != [6, 1,2,3,4,5,6]) ||
  983.     anyof(dimsof(transpose(x))               != [6, 6,2,3,4,5,1]) ||
  984.     anyof(dimsof(transpose(x,[1,2]))         != [6, 2,1,3,4,5,6]) ||
  985.     anyof(dimsof(transpose(x,[1,0]))         != [6, 6,2,3,4,5,1]) ||
  986.     anyof(dimsof(transpose(x,2))             != [6, 6,1,2,3,4,5]) ||
  987.     anyof(dimsof(transpose(x,0))             != [6, 2,3,4,5,6,1]) ||
  988.     anyof(dimsof(transpose(x,3))             != [6, 5,6,1,2,3,4]) ||
  989.     anyof(dimsof(transpose(x,[4,6,3],[2,5])) != [6, 1,5,6,3,2,4])) {
  990.   goofs++;
  991.   "**FAILURE** of transpose test 1";
  992. }
  993. y= transpose(x,[4,6,3],[2,5]);
  994. if (y(1,5,6,3,2,4)!=x(1,2,3,4,5,6) || y(1,3,4,1,2,1)!=x(1,2,1,1,3,4)) {
  995.   goofs++;
  996.   "**FAILURE** of transpose test 2";
  997. }
  998.  
  999. x= y= [];
  1000. if (do_stats) "H "+print(yorick_stats());
  1001.  
  1002. /* ------------------------------------------------------------------------- */
  1003.  
  1004. write, "Test struct instancing and indexing...";
  1005.  
  1006. /* Test structs. */
  1007.  
  1008. struct Stest {
  1009.   char a;
  1010.   short b;
  1011.   double c(4);
  1012.   int d(2,3), e(5);
  1013.   complex f(2);
  1014. }
  1015.  
  1016. x= Stest(a='A', b=13, c=[2,-4,6,-8],
  1017.      d=[[-1,2],[-3,4],[-5,6]], e=[10,20,30,40,50], f=[1i,2-2i]);
  1018. if (x.a!='A' || x.b!=13 || anyof(x.c!=[2.,-4.,6.,-8.]) ||
  1019.     anyof(x.d!=[[-1,2],[-3,4],[-5,6]]) || anyof(x.e!=[10,20,30,40,50]) ||
  1020.     anyof(x.f!=[1i,2-2i])) {
  1021.   goofs++;
  1022.   "**FAILURE** of - struct instance declaration";
  1023. }
  1024.  
  1025. y= array(Stest, 2);
  1026. y(..)= x;
  1027. y.a(2)= 'B';
  1028. y(2).b= -x.b;
  1029. y.c(..,2)= x.c(::-1);
  1030. y(2).d(,1:2)= transpose(x.d(,1:2));
  1031. y.e(::-1,2)= x.e;
  1032. y(2).f= conj(x.f);
  1033.  
  1034. if (x!=y(1) || y(2).a!='B' || y(2).b!=-13 || anyof(y(2).c!=[-8.,6.,-4.,2.]) ||
  1035.     anyof(y(2).d!=[[-1,-3],[2,4],[-5,6]]) ||
  1036.     anyof(y(2).e!=[50,40,30,20,10]) || anyof(y(2).f!=[-1i,2+2i])) {
  1037.   goofs++;
  1038.   "**FAILURE** of - struct instance array indexing";
  1039. }
  1040.  
  1041. x= y= [];
  1042. if (do_stats) "I "+print(yorick_stats());
  1043.  
  1044. /* ------------------------------------------------------------------------- */
  1045.  
  1046. write, "Test range functions...";
  1047.  
  1048. /* Test range functions. */
  1049.  
  1050. x= [[[3,7,5],[-4,2,-6]], [[-1,-4,-2],[0,4,8]],
  1051.     [[-1,-5,2],[1,0,0]], [[9,8,7],[-9,9,-6]]];
  1052. y= x+0.5;
  1053.  
  1054. if (anyof(x(,-:1:2,,1)!=[[[3,7,5],[3,7,5]],[[-4,2,-6],[-4,2,-6]]])) {
  1055.   goofs++;
  1056.   "**FAILURE** of - pseudo range function (-)";
  1057. }
  1058.  
  1059. if (anyof(x(,..)!=x) || anyof(x(..,:)!=x) || anyof(x(,*)!=x(,1:8)) ||
  1060.     anyof(x(*,)!=x(1:6,1,))) {
  1061.   goofs++;
  1062.   "**FAILURE** of - rubber range function (.. or *)";
  1063. }
  1064.  
  1065. if (anyof(x(,pcen,)(,uncp,)!=x) || anyof(y(,pcen,)(,uncp,)!=y)) {
  1066.   goofs++;
  1067.   "**FAILURE** of - uncp range function";
  1068. }
  1069.  
  1070. if (anyof(x(,pcen,)(,2:-1,)!=x(,zcen,)) ||
  1071.     anyof(x(,pcen,)(,1,)!=x(,1,)) || anyof(x(,pcen,)(,0,)!=x(,0,)) ||
  1072.     anyof(y(,pcen,)!=x(,pcen,)+0.5)) {
  1073.   goofs++;
  1074.   "**FAILURE** of - pcen range function";
  1075. }
  1076.  
  1077. if (anyof(x(,zcen,)!=[[[-.5,4.5,-.5]],[[-.5,0,3]],
  1078.               [[0,-2.5,1]],[[0,8.5,.5]]]) ||
  1079.     anyof(y(,zcen,)!=[[[-.5,4.5,-.5]],[[-.5,0,3]],
  1080.               [[0,-2.5,1]],[[0,8.5,.5]]] + 0.5)) {
  1081.   goofs++;
  1082.   "**FAILURE** of - zcen range function";
  1083. }
  1084.  
  1085. if (anyof(x(,dif,)!=[[[-7,-5,-11]],[[1,8,10]],[[2,5,-2]],[[-18,1,-13]]]) ||
  1086.     anyof(y(,dif,)!=[[[-7,-5,-11]],[[1,8,10]],[[2,5,-2]],[[-18,1,-13]]])) {
  1087.   goofs++;
  1088.   "**FAILURE** of - dif range function";
  1089. }
  1090.  
  1091. if (anyof(x(,psum,)!=[[[3,7,5],[-1,9,-1]], [[-1,-4,-2],[-1,0,6]],
  1092.               [[-1,-5,2],[0,-5,2]], [[9,8,7],[0,17,1]]]) ||
  1093.     anyof(y(,psum,)!=[[[3,7,5],[-1,9,-1]], [[-1,-4,-2],[-1,0,6]],
  1094.               [[-1,-5,2],[0,-5,2]], [[9,8,7],[0,17,1]]] +
  1095.       [0.5,1.0](-,))) {
  1096.   goofs++;
  1097.   "**FAILURE** of - psum range function";
  1098. }
  1099.  
  1100. if (anyof(x(,cum,)!=[[[0,0,0],[3,7,5],[-1,9,-1]],
  1101.              [[0,0,0],[-1,-4,-2],[-1,0,6]],
  1102.              [[0,0,0],[-1,-5,2],[0,-5,2]],
  1103.              [[0,0,0],[9,8,7],[0,17,1]]]) ||
  1104.     anyof(y(,cum,)!=[[[0,0,0],[3,7,5],[-1,9,-1]],
  1105.              [[0,0,0],[-1,-4,-2],[-1,0,6]],
  1106.              [[0,0,0],[-1,-5,2],[0,-5,2]],
  1107.              [[0,0,0],[9,8,7],[0,17,1]]] +
  1108.       [0.0,0.5,1.0](-,))) {
  1109.   goofs++;
  1110.   "**FAILURE** of - cum range function";
  1111. }
  1112.  
  1113. if (anyof(x(zcen,dif,)!=[[[-6,-8]],[[4.5,9]],[[3.5,1.5]],[[-8.5,-6]]]) ||
  1114.     anyof(y(zcen,dif,)!=[[[-6,-8]],[[4.5,9]],[[3.5,1.5]],[[-8.5,-6]]])) {
  1115.   goofs++;
  1116.   "**FAILURE** of - zcen,dif multiple range function";
  1117. }
  1118.  
  1119. if (anyof(x(min,,max)!=[7,0]) || anyof(y(,,max)(min,)!=[7,1]+0.5)) {
  1120.   goofs++;
  1121.   "**FAILURE** of - min or max range function";
  1122. }
  1123.  
  1124. if (anyof(x(,ptp,)!=[[-7,-5,-11],[1,8,10],[2,5,-2],[-18,1,-13]]) ||
  1125.     anyof(y(,ptp,)!=[[-7,-5,-11],[1,8,10],[2,5,-2],[-18,1,-13]])) {
  1126.   goofs++;
  1127.   "**FAILURE** of - ptp range function";
  1128. }
  1129.  
  1130. if (anyof(x(,mnx,)!=[[2, 2, 2], [1, 1, 1], [1, 1, 2], [2, 1, 2]]) ||
  1131.     anyof(y(,mnx,)!=[[2, 2, 2], [1, 1, 1], [1, 1, 2], [2, 1, 2]])) {
  1132.   goofs++;
  1133.   "**FAILURE** of - mnx range function";
  1134. }
  1135.  
  1136. if (anyof(x(,mxx,)!=3-x(,mnx,)) ||
  1137.     anyof(y(,mxx,)!=3-y(,mnx,))) {
  1138.   goofs++;
  1139.   "**FAILURE** of - mxx range function";
  1140. }
  1141.  
  1142. if (anyof(x(,sum,)!=x(,1,)+x(,2,)) ||
  1143.     anyof(y(,sum,)!=y(,1,)+y(,2,))) {
  1144.   goofs++;
  1145.   "**FAILURE** of - sum range function";
  1146. }
  1147.  
  1148. if (anyof(x(,avg,)!=0.5*(x(,1,)+x(,2,))) ||
  1149.     anyof(y(,avg,)!=0.5*(y(,1,)+y(,2,)))) {
  1150.   goofs++;
  1151.   "**FAILURE** of - avg range function";
  1152. }
  1153.  
  1154. if (anyof(abs(x(,rms,)-0.5*abs(x(,1,)-x(,2,)))>1.e-10) ||
  1155.     anyof(abs(y(,rms,)-0.5*abs(y(,1,)-y(,2,)))>1.e-10)) {
  1156.   goofs++;
  1157.   "**FAILURE** of - rms range function";
  1158. }
  1159.  
  1160. x= [[1,2,3],[-5,5,-8]];
  1161. y= [[1,1],[-1,-1],[0,1]];
  1162.  
  1163. if (anyof(x(+,)*y(,+) != [[-1,-10],[2,-18]]) ||
  1164.     anyof(x(,+)*y(+,) != [[-4,7,-5],[4,-7,5],[-5,5,-8]])) {
  1165.   goofs++;
  1166.   "**FAILURE** of + matrix multiply function";
  1167. }
  1168.  
  1169. x+= 0i;
  1170.  
  1171. if (anyof(x(+,)*y(,+) != [[-1,-10],[2,-18]]) ||
  1172.     anyof(x(,+)*y(+,) != [[-4,7,-5],[4,-7,5],[-5,5,-8]])) {
  1173.   goofs++;
  1174.   "**FAILURE** of + complex matrix multiply function";
  1175. }
  1176.  
  1177. x= y= [];
  1178. if (do_stats) "J "+print(yorick_stats());
  1179.  
  1180. /* ------------------------------------------------------------------------- */
  1181.  
  1182. write, "Test math functions...";
  1183.  
  1184. /* Test math functions. */
  1185.  
  1186. x= pi/4;  y= [3*pi/4, pi/6];
  1187.  
  1188. if (not_near(sin(x),sqrt(0.5)) || not_near(sin(y),[sqrt(0.5),0.5]) ||
  1189.     not_near(cos(x),sqrt(0.5)) || not_near(cos(y),[-sqrt(0.5),sqrt(.75)]) ||
  1190.     not_near(tan(x),1) || not_near(tan(y),[-1,1/sqrt(3)])) {
  1191.   goofs++;
  1192.   "**FAILURE** of - sin, cos, tan, or sqrt function";
  1193. }
  1194.  
  1195. if (not_near(asin(sqrt(0.5)),x) ||
  1196.     not_near(asin([sqrt(0.5),0.5]),y-[pi/2,0]) ||
  1197.     not_near(acos(sqrt(0.5)),x) || not_near(acos([-sqrt(0.5),sqrt(.75)]),y) ||
  1198.     not_near(atan(1),x) || not_near(atan([-1,1/sqrt(3)]),y-[pi,0])) {
  1199.   goofs++;
  1200.   "**FAILURE** of - asin, acos, atan, or sqrt function";
  1201. }
  1202.  
  1203. if (not_near(atan(5,5),x) || not_near(atan([.1,1],[-.1,sqrt(3)]),y)) {
  1204.   goofs++;
  1205.   "**FAILURE** of - 2 argument atan function";
  1206. }
  1207.  
  1208. if (not_near(exp(1i*x),cos(x)+1i*sin(x)) ||
  1209.     not_near(exp(1i*y),cos(y)+1i*sin(y)) ||
  1210.     not_near(cos(1i*x), 0.5*(exp(-x)+exp(x))) ||
  1211.     not_near(cos(1i*y), 0.5*(exp(-y)+exp(y))) ||
  1212.     not_near(sin(1i*x), 0.5i*(exp(x)-exp(-x))) ||
  1213.     not_near(sin(1i*y), 0.5i*(exp(y)-exp(-y))) ||
  1214.     not_near(tan(1i*x), 1i*(exp(x)-exp(-x))/(exp(-x)+exp(x))) ||
  1215.     not_near(tan(1i*y), 1i*(exp(y)-exp(-y))/(exp(-y)+exp(y)))) {
  1216.   goofs++;
  1217.   "**FAILURE** of - (complex) exp, sin, cos, or tan function";
  1218. }
  1219.  
  1220. if (not_near(exp(1),2.718281828459) ||
  1221.     not_near(exp([-.5,2.5]), [1,exp(1)^3]/sqrt(exp(1))) ||
  1222.     not_near(exp(x),cosh(x)+sinh(x)) ||
  1223.     not_near(exp(y),cosh(y)+sinh(y)) ||
  1224.     not_near(cosh(x), 0.5*(exp(-x)+exp(x))) ||
  1225.     not_near(cosh(y), 0.5*(exp(-y)+exp(y))) ||
  1226.     not_near(sinh(x), 0.5*(exp(x)-exp(-x))) ||
  1227.     not_near(sinh(y), 0.5*(exp(y)-exp(-y))) ||
  1228.     not_near(tanh(x), (exp(x)-exp(-x))/(exp(-x)+exp(x))) ||
  1229.     not_near(tanh(y), (exp(y)-exp(-y))/(exp(-y)+exp(y)))) {
  1230.   goofs++;
  1231.   "**FAILURE** of -  exp, sinh, cosh, or tanh function";
  1232. }
  1233.  
  1234. if (not_near(sech(x), 2/(exp(-x)+exp(x))) ||
  1235.     not_near(sech(y), 2/(exp(-y)+exp(y))) ||
  1236.     not_near(csch(x), 2/(exp(x)-exp(-x))) ||
  1237.     not_near(csch(y), 2/(exp(y)-exp(-y))) ||
  1238.     anyof(sech([1.e6,-1.e6])) || anyof(csch([1.e6,-1.e6]))) {
  1239.   goofs++;
  1240.   "**FAILURE** of -  sech or csch function";
  1241. }
  1242.  
  1243. if (not_near(acosh(cosh(x)), x) || not_near(acosh(cosh(y)), y) ||
  1244.     not_near(asinh(sinh(x)), x) || not_near(asinh(sinh(y)), y) ||
  1245.     not_near(atanh(tanh(x)), x) || not_near(atanh(tanh(y)), y)) {
  1246.   goofs++;
  1247.   "**FAILURE** of -  acosh, asinh, or atanh function";
  1248. }
  1249.  
  1250. if (not_near(exp(1i*x),cosh(1i*x)+sinh(1i*x)) ||
  1251.     not_near(exp(1i*y),cosh(1i*y)+sinh(1i*y)) ||
  1252.     not_near(cosh(1i*x), 0.5*(exp(-1i*x)+exp(1i*x))) ||
  1253.     not_near(cosh(1i*y), 0.5*(exp(-1i*y)+exp(1i*y))) ||
  1254.     not_near(sinh(1i*x), 0.5*(exp(1i*x)-exp(-1i*x))) ||
  1255.     not_near(sinh(1i*y), 0.5*(exp(1i*y)-exp(-1i*y))) ||
  1256.     not_near(tanh(1i*x), (exp(1i*x)-exp(-1i*x))/(exp(-1i*x)+exp(1i*x))) ||
  1257.     not_near(tanh(1i*y), (exp(1i*y)-exp(-1i*y))/(exp(-1i*y)+exp(1i*y)))) {
  1258.   goofs++;
  1259.   "**FAILURE** of -  (complex) exp, sinh, cosh, or tanh function";
  1260. }
  1261.  
  1262. if (not_near(log(exp(x)), x) || not_near(log(exp(y)), y) ||
  1263.     not_near(log10(10^x), x) || not_near(log10(10^y), y) ||
  1264.     not_near(log10(x*y),log10(x)+log10(y)) ||
  1265.     not_near(log(x*y),log(x)+log(y)) ||
  1266.     not_near(exp(x+y),exp(x)*exp(y)) ||
  1267.     not_near(log10([1.e5,1.e-7]),[5,-7]) ||
  1268.     not_near(log(10),1/log10(exp(1))) ||
  1269.     not_near(log(10)*log10(x),log(x)) || not_near(log(10)*log10(y),log(y))) {
  1270.   goofs++;
  1271.   "**FAILURE** of -  log, log10, or exp function";
  1272. }
  1273.  
  1274. if (anyof(abs(x)!=x) || anyof(abs(-x)!=x) ||
  1275.     anyof(abs(y)!=y) || anyof(abs(-y)!=y)) {
  1276.   goofs++;
  1277.   "**FAILURE** of -  abs function";
  1278. }
  1279.  
  1280. if (anyof(ceil(3.7)!=4) || anyof(ceil([-3.7,2.1])!=[-3,3]) ||
  1281.     anyof(floor(3.7)!=3) || anyof(floor([-3.7,2.1])!=[-4,2])) {
  1282.   goofs++;
  1283.   "**FAILURE** of -  ceil or floor function";
  1284. }
  1285.  
  1286. if (not_near(abs(x,y,x,y),sqrt(2*(x^2+y^2)))) {
  1287.   goofs++;
  1288.   "**FAILURE** of -  multiargument abs function";
  1289. }
  1290.  
  1291. if (anyof(sign(x)!=1) || anyof(sign(-x)!=-1) ||
  1292.     anyof(sign(y)!=1) || anyof(sign(-y)!=-1) ||
  1293.     sign(0)!=1 || sign(0.0)!=1 || sign(0i)!=1 ||
  1294.     not_near(sign(exp(1i*y+x)),exp(1i*y))) {
  1295.   goofs++;
  1296.   "**FAILURE** of -  sign function";
  1297. }
  1298.  
  1299. if (conj(x+1i)!=x-1i || anyof(conj(y+1i)!=y-1i)) {
  1300.   goofs++;
  1301.   "**FAILURE** of -  conj function";
  1302. }
  1303.  
  1304. if (random()<0.0 || random()>1.0 ||
  1305.     anyof(dimsof(random(3,4,2))!=[3,3,4,2])) {
  1306.   goofs++;
  1307.   "**FAILURE** of -  random function";
  1308. }
  1309.  
  1310. if (min(x)!=x || min(y)!=pi/6 || anyof(min(x,y)!=[pi/4,pi/6]) ||
  1311.     max(x)!=x || max(y)!=3*pi/4 || anyof(max(x,y)!=[3*pi/4,pi/4])) {
  1312.   goofs++;
  1313.   "**FAILURE** of -  min or max function";
  1314. }
  1315.  
  1316. if (sum(x)!=x || not_near(sum(y), 11*pi/12) ||
  1317.     avg(x)!=x || not_near(avg(y), 11*pi/24)) {
  1318.   goofs++;
  1319.   "**FAILURE** of -  sum or avg function";
  1320. }
  1321.  
  1322. if (allof([1,0]) || !allof([1,1]) || anyof([0,0]) || !anyof([1,0]) ||
  1323.     noneof([1,0]) || !noneof([0,0]) || nallof([1,1]) || !nallof([1,0])) {
  1324.   goofs++;
  1325.   "**FAILURE** of -  allof, anyof, noneof, or nallof function";
  1326. }
  1327.  
  1328. if (anyof(where([[0,1,0,0],[0,0,0,1]])!=[2,8]) ||
  1329.     anyof(where2([[0,1,0,0],[0,0,0,1]])!=[[2,1],[4,2]])) {
  1330.   goofs++;
  1331.   "**FAILURE** of -  where or where2 function";
  1332. }
  1333.  
  1334. x= Stest(a='A', b=13, c=[2,-4,6,-8],
  1335.      d=[[-1,2],[-3,4],[-5,6]], e=[10,20,30,40,50], f=[1i,2-2i]);
  1336. y= array(x, 2);
  1337. y(1).b= 8;  y(2).b=19;
  1338. if (anyof(merge(cA,iS,[1,1,0])!=[1,2,1]) ||
  1339.     anyof(merge(lS,sA,[0,0,1])!=[1,2,1]) ||
  1340.     anyof(merge(iA,dS,[1,0,1])!=[1,1,2]) ||
  1341.     anyof(merge(lA,fA,[[1,1],[0,0]])!=[[1,2],[1,2]]) ||
  1342.     anyof(merge(zA,dA,[[1,0],[0,1]])!=[[1,1],[2,2]]) ||
  1343.     anyof(merge(cA,cA,[[1,0],[0,1]])!=[[1,1],[2,2]]) ||
  1344.     anyof(merge(sA,sA,[[1,0],[0,1]])!=[[1,1],[2,2]]) ||
  1345.     anyof(merge(y,x,[1,0,1])!=[y(1),x,y(2)]) ||
  1346.     anyof(merge(dA,[],[1,1])!=dA) ||
  1347.     anyof(merge([],lA,[0,0])!=lA) ||
  1348.     anyof(merge2(lA,zA(::-1),[1,0])!=[1,1])) {
  1349.   goofs++;
  1350.   "**FAILURE** of -  merge or merge2 function";
  1351. }
  1352. x= y= [];
  1353.  
  1354. if (do_stats) "K "+print(yorick_stats());
  1355.  
  1356. /* ------------------------------------------------------------------------- */
  1357.  
  1358. write, "Test informational functions...";
  1359.  
  1360. /* Test informational functions. */
  1361.  
  1362. if (structof(3.5)!=double || structof('\61')!=char ||
  1363.     structof([4,5,6])!=long || structof([1n,-1n])!=int ||
  1364.     structof([3s,4s])!=short || structof(4.4f)!=float ||
  1365.     structof(1i)!=complex || structof(array(Stest,2,2))!=Stest ||
  1366.     structof([&[1,2,3],&[],&[3.5,1.2]])!=pointer || structof("yo")!=string) {
  1367.   goofs++;
  1368.   "**FAILURE** of - structof function or structure != operation";
  1369. }
  1370.  
  1371. if (anyof(dimsof([[2,4,6],[1,3,5]])!=[2,3,2]) || anyof(dimsof(5)!=[0]) ||
  1372.     anyof(dimsof(array(short,5,-4:-1,3:5,0:1))!=[4,5,4,3,2]) ||
  1373.     anyof(dimsof([1,2,3](-,),[1,2])!=[2,2,3])) {
  1374.   goofs++;
  1375.   "**FAILURE** of - dimsof function";
  1376. }
  1377.  
  1378. dummy= use_origins(1);
  1379. if (anyof(orgsof([[2,4,6],[1,3,5]])!=[2,indgen(0),indgen(0)]) ||
  1380.     anyof(orgsof(array(short,5,-4:-1,3:5,0:1))!=[4,indgen(0),-4,3,0])) {
  1381.   goofs++;
  1382.   "**FAILURE** of - orgsof function";
  1383. }
  1384. dummy= [];
  1385.  
  1386. if (numberof([[2,4,6],[1,3,5]])!=6 || numberof(3.5)!=1 || numberof([])!=0 ||
  1387.     numberof(array(short,5,-4:-1,3:5,0:1))!=120) {
  1388.   goofs++;
  1389.   "**FAILURE** of - numberof function";
  1390. }
  1391.  
  1392. if (sizeof([[2,4,6],[1,3,5]])!=6*sizeof(long) || sizeof(3.5)!=sizeof(double) ||
  1393.     sizeof(array(short,5,-4:-1,3:5,0:1))!=120*sizeof(short)) {
  1394.   goofs++;
  1395.   "**FAILURE** of - sizeof function";
  1396. }
  1397.  
  1398. if (typeof(3.5)!="double" || typeof('\61')!="char" ||
  1399.     typeof([4,5,6])!="long" || typeof([1n,-1n])!="int" ||
  1400.     typeof([3s,4s])!="short" || typeof(4.4f)!="float" ||
  1401.     typeof(1i)!="complex" || typeof(array(Stest,2,2))!="struct_instance" ||
  1402.     typeof(Stest)!="struct_definition" || typeof(3:52:4)!="range" ||
  1403.     typeof([])!="void" || typeof()!="void" || typeof("yo")!="string" ||
  1404.     typeof(&[3,4])!="pointer") {
  1405.   goofs++;
  1406.   "**FAILURE** of - typeof function";
  1407. }
  1408.  
  1409. if (nameof(Stest)!="Stest" || nameof(not_near)!="not_near") {
  1410.   goofs++;
  1411.   "**FAILURE** of - nameof function";
  1412. }
  1413.  
  1414. if (!is_array([3,4]) || !is_array(0) || is_array() || is_array(not_near) ||
  1415.     is_array(Stest)) {
  1416.   goofs++;
  1417.   "**FAILURE** of - is_array function";
  1418. }
  1419.  
  1420. if (is_void(7) || !is_void() || !is_void([]) || is_void(not_near)) {
  1421.   goofs++;
  1422.   "**FAILURE** of - is_void function";
  1423. }
  1424.  
  1425. if (is_func(7) || is_func() || !is_func(not_near) || is_func(Stest)) {
  1426.   goofs++;
  1427.   "**FAILURE** of - is_func function";
  1428. }
  1429.  
  1430. if (is_struct(7) || is_struct() || is_struct(not_near) ||
  1431.     !is_struct(Stest)) {
  1432.   goofs++;
  1433.   "**FAILURE** of - is_struct function";
  1434. }
  1435.  
  1436. if (is_range(7) || is_range() || is_range(not_near) ||
  1437.     is_range(Stest) || !is_range(3:4)) {
  1438.   goofs++;
  1439.   "**FAILURE** of - is_range function";
  1440. }
  1441.  
  1442. func junk(x)
  1443. {
  1444.   extern junk_test;
  1445.   return junk_test= am_subroutine();
  1446. }
  1447. junk_test= 0;
  1448. junk;
  1449. if (!junk_test || junk()) {
  1450.   goofs++;
  1451.   "**FAILURE** of - am_subroutine function";
  1452. }
  1453.  
  1454. if (do_stats) "L "+print(yorick_stats());
  1455.  
  1456. /* ------------------------------------------------------------------------- */
  1457.  
  1458. write, "Test func declarations...";
  1459.  
  1460. /* Test func declarations. */
  1461.  
  1462. func junk(&w,x,&y,z,..,k=,l=,m=)
  1463. {
  1464.   rslt= [w,x,y,z,k,l,m];
  1465.   while (more_args()) grow, rslt, next_arg();
  1466.   w=x=y=z=k=l=m=16;
  1467.   return rslt;
  1468. }
  1469. a= b= c= d= -2;
  1470. if (anyof(junk(k=5,a,b,m=c,3,4,8,9,l=d,10,11)!=[-2,-2,3,4,5,-2,-2,8,9,10,11])
  1471.     || a!=16 || b!=-2 || c!=-2 || d!=-2) {
  1472.   goofs++;
  1473.   "**FAILURE** of - complicated func declaration";
  1474. }
  1475. junk= [];
  1476.  
  1477. /* ------------------------------------------------------------------------- */
  1478.  
  1479. write, "Test binary I/O functions...";
  1480.  
  1481. /* Test binary I/O functions. */
  1482.  
  1483. f= createb("junkb.pdb");
  1484.  
  1485. if (is_stream(7) || is_stream() || is_stream(not_near) ||
  1486.     is_stream(Stest) || !is_stream(f)) {
  1487.   goofs++;
  1488.   "**FAILURE** of - is_stream function";
  1489. }
  1490.  
  1491. x= ["whoa", "okay"];
  1492. y= [&(1+0), &[1.5,2.5,3.5], &[]];
  1493. z= Stest(a='A', b=13, c=[2,-4,6,-8],
  1494.      d=[[-1,2],[-3,4],[-5,6]], e=[10,20,30,40,50], f=[1i,2-2i]);
  1495.  
  1496. save, f, x, y, z;
  1497. close, f;
  1498. f= updateb("junkb.pdb");
  1499. save, f, iS, lS, dS;
  1500. save, f, cA, sA, iA, lA, fA, dA, zA;
  1501. f.sA= [-91,57];
  1502. close, f;
  1503.  
  1504. f= openb("junkb.pdb");
  1505. x= y= z= [];
  1506. restore, f, x, y, z;
  1507. if (typeof(x)!="string" || typeof(y)!="pointer" ||
  1508.     anyof(dimsof(x)!=[1,2]) || anyof(dimsof(y)!=[1,3]) ||
  1509.     anyof(x!=["whoa", "okay"]) || typeof(*y(1))!="long" ||
  1510.     !is_void(*y(3)) || anyof(*y(2)!=[1.5,2.5,3.5]) ||
  1511.     structof(z)!=Stest || z.a!='A' || anyof(dimsof(z.d)!=[2,2,3]) ||
  1512.     anyof(dimsof(z.f)!=[1,2]) || anyof(z.f!=[1i,2-2i])) {
  1513.   goofs++;
  1514.   "**FAILURE** of - restore or save function";
  1515. }
  1516. if (f.iS!=iS || f.lS!=lS || f.dS!=dS ||
  1517.     anyof(f.cA!=cA) || anyof(f.sA!=[-91,57]) || anyof(f.iA!=iA) ||
  1518.     anyof(f.lA!=lA) || anyof(f.fA!=fA) || anyof(f.dA!=dA) ||
  1519.     anyof(f.zA!=zA) || typeof(f.cA)!="char" || typeof(f.sA)!="short" ||
  1520.     typeof(f.iA)!="int" || typeof(f.lA)!="long" || typeof(f.fA)!="float" ||
  1521.     typeof(f.dA)!="double" || typeof(f.zA)!="complex") {
  1522.   goofs++;
  1523.   "**FAILURE** of - f.var syntax or save function";
  1524. }
  1525. close, f;
  1526.  
  1527. remove, "junkb.pdb"
  1528.  
  1529. if (do_stats) "M "+print(yorick_stats());
  1530.  
  1531. /* ------------------------------------------------------------------------- */
  1532.  
  1533. write, "Test ASCII I/O functions...";
  1534.  
  1535. /* Test ASCII I/O functions. */
  1536.  
  1537. f= open("junkt.txt", "w");
  1538. write,f, "The first line.";
  1539. write,f, dA;
  1540. write,f, sA-7, fA+5;
  1541. write,f, format="blah %s %d %e\n", "wow", lA+6, dA-20;
  1542. close,f;
  1543.  
  1544. f= open("junkt.txt", "r+");
  1545. if (rdline(f)!=" The first line.") {
  1546.   goofs++;
  1547.   "**FAILURE** of - rdline or write function";
  1548. }
  1549. backup, f;
  1550. if (rdline(f)!=" The first line.") {
  1551.   goofs++;
  1552.   "**FAILURE** of - backup function";
  1553. }
  1554. mark= bookmark(f);
  1555. x= 0*dA;
  1556. if (read(f,x)!=2 || anyof(x!=dA)) {
  1557.   goofs++;
  1558.   "**FAILURE** of - read or write function";
  1559. }
  1560. y= 0*sA;
  1561. if (read(f,y,x)!=4 || anyof(y!=sA-7) || anyof(x!=fA+5)) {
  1562.   goofs++;
  1563.   "**FAILURE** of - read or write function ";
  1564. }
  1565. y= 0*lA;
  1566. mark2= bookmark(f);
  1567. if (read(f, format="blah wow %d %e\n", y,x)!=4 ||
  1568.     anyof(y!=lA+6) || anyof(x!=dA-20)) {
  1569.   backup, f, mark2;
  1570.   if (read(f, format="blah wow %d %e", y,x)!=4 ||
  1571.       anyof(y!=lA+6) || anyof(x!=dA-20)) {
  1572.     goofs++;
  1573.     "**FAILURE** of -  formatted read or write function";
  1574.   } else {
  1575.     /* this OS does not like trailing \n in read formats */
  1576.     "**WARNING** Yorick formatted read peculiarity -- see testp.i";
  1577.   }
  1578. }
  1579. backup, f, mark;
  1580. if (read(f,x)!=2 || anyof(x!=dA)) {
  1581.   goofs++;
  1582.   "**FAILURE** of -  bookmark or backup function";
  1583. }
  1584. write,f, "Last line.";
  1585. close, f;
  1586. f= open("junkt.txt");
  1587. if (rdline(f,7)(7)!=" Last line.") {
  1588.   goofs++;
  1589.   "**FAILURE** of -  write to append to end of text";
  1590. }
  1591. close, f;
  1592.  
  1593. remove, "junkt.txt";
  1594.  
  1595. if (do_stats) "N "+print(yorick_stats());
  1596.  
  1597. /* ------------------------------------------------------------------------- */
  1598.  
  1599. write, "Test string manipulation functions...";
  1600.  
  1601. /* Test string manipulation functions. */
  1602.  
  1603. if (strlen("abc")!=3 ||
  1604.     anyof(strlen([[string(),"","a"],["axx","ab","abcd"]])!=
  1605.       [[0,0,1],[3,2,4]])) {
  1606.   goofs++;
  1607.   "**FAILURE** of - strlen function";
  1608. }
  1609.  
  1610. if (anyof(strtok("abc    1.23    xxx")!=["abc", "   1.23    xxx"]) ||
  1611.     anyof(strtok(["abc    1.23    xxx","c","1.5"], "\t c")!=
  1612.       [["ab", "    1.23    xxx"],string(),["1.5",string()]])) {
  1613.   goofs++;
  1614.   "**FAILURE** of - strtok function";
  1615. }
  1616.  
  1617. if (!strmatch("abc", "b") || strmatch("abc", "B") ||
  1618.     !strmatch("abc", "B", 1) ||
  1619.     anyof(strmatch(["abc","aBC"], "B")!=[0,1])) {
  1620.   goofs++;
  1621.   "**FAILURE** of - strmatch function";
  1622. }
  1623.  
  1624. if (strpart("abc", 1:1)!="a" || strpart("abc", 2:10)!="bc" ||
  1625.     strpart("abc", :-1)!="ab" || strpart("abc", :-5)!="" ||
  1626.     anyof(strpart(["abc","yowza"],3:)!=["c","wza"])) {
  1627.   goofs++;
  1628.   "**FAILURE** of - strpart function";
  1629. }
  1630.  
  1631. if (do_stats) "O "+print(yorick_stats());
  1632.  
  1633. /* ------------------------------------------------------------------------- */
  1634.  
  1635. write, "Test list functions...";
  1636.  
  1637. l= _lst(1.5, structof(z), _lst([],z), _prt);
  1638. #if 0
  1639. write, "<Begin output from _prt list (15 lines gibberish)>";
  1640. _prt, l;
  1641. write, "<End output from _prt list (15 lines gibberish)>";
  1642. #endif
  1643. if (_len(l)!=4) {
  1644.   goofs++;
  1645.   "**FAILURE** of - _lst or _len function";
  1646. }
  1647. if (_car(l)!=1.5 || _car(l,1)!=1.5 || _car(l,2)!=Stest ||
  1648.     typeof(_car(l,3))!="list" || _car(l,4)!=_prt ||
  1649.     !is_void(_car(_car(l,3)))) {
  1650.   goofs++;
  1651.   "**FAILURE** of - _lst or _car function";
  1652. }
  1653. if (_car(_cdr(l))!=Stest || _car(_cdr(l,3))!=_prt ||
  1654.     !is_void(_cdr(l,4))) {
  1655.   goofs++;
  1656.   "**FAILURE** of - _cdr function";
  1657. }
  1658. m= _cpy(l,2);
  1659. if (_len(m)!=2 || _car(m)!=1.5 || _car(m,2)!=Stest || _len(_cpy(l))!=4) {
  1660.   goofs++;
  1661.   "**FAILURE** of - _cpy function";
  1662. }
  1663. if (_car(m,2,2.5)!=Stest || _car(l,2)!=Stest || _car(m,2)!=2.5) {
  1664.   goofs++;
  1665.   "**FAILURE** of - _car set function";
  1666. }
  1667. n= _cat(m, _cpy(_cdr(l,2)));
  1668. if (n!=m || _len(m)!=4 || _len(n)!=4 || _car(n,4)!=_prt) {
  1669.   goofs++;
  1670.   "**FAILURE** of - _cat function";
  1671. }
  1672. if (_car(_cdr(m,3,[]))!=_prt || !is_void(_cdr(n,3)) ||
  1673.     !is_void(_cdr(n,3,_lst(_len))) || _car(m,4)!=_len ||
  1674.     _car(l,4)!=_prt) {
  1675.   goofs++;
  1676.   "**FAILURE** of - _cdr set function";
  1677. }
  1678. n= _map(typeof, m);
  1679. if (_car(n)!="double" || _car(n,2)!="double" ||
  1680.     _car(n,3)!="list" || _car(n,4)!="builtin") {
  1681.   goofs++;
  1682.   "**FAILURE** of - _map set function";
  1683. }
  1684. m= _rev(m);
  1685. if (_car(m,4)!=1.5 || _car(m,3)!=2.5 ||
  1686.     typeof(_car(m,2))!="list" || _car(m)!=_len ||
  1687.     !is_void(_car(_car(m,2)))) {
  1688.   goofs++;
  1689.   "**FAILURE** of - _rev function";
  1690. }
  1691. l= m= n= [];
  1692.  
  1693. if (do_stats) "P "+print(yorick_stats());
  1694.  
  1695. /* ------------------------------------------------------------------------- */
  1696.  
  1697. write, "Test catch function...";
  1698.  
  1699. func junk(type)
  1700. {
  1701.   if (catch(0x01)) {
  1702.     if (type!=0x01) {
  1703.       goofs++;
  1704.       "**FAILURE** of - catch function - misidentified error as math";
  1705.     }
  1706.     return 0x01;
  1707.   }
  1708.   if (catch(0x02)) {
  1709.     if (type!=0x02) {
  1710.       goofs++;
  1711.       "**FAILURE** of - catch function - misidentified error as io";
  1712.     }
  1713.     return 0x02;
  1714.   }
  1715.   if (catch(0x04)) {
  1716.     if (type!=0x04) {
  1717.       goofs++;
  1718.       "**FAILURE** of - catch function - misidentified error as C-c";
  1719.     }
  1720.     return 0x04;
  1721.   }
  1722.   if (catch(0x08)) {
  1723.     if (type!=0x08) {
  1724.       goofs++;
  1725.       "**FAILURE** of - catch function - misidentified error as YError";
  1726.     }
  1727.     return 0x08;
  1728.   }
  1729.   if (catch(0x10)) {
  1730.     if (type!=0x10) {
  1731.       goofs++;
  1732.       "**FAILURE** of - catch function - misidentified error as interpreted";
  1733.     } else if (catch_message!="---test error, should be caught---") {
  1734.       goofs++;
  1735.       "**FAILURE** of - catch function - catch_message set incorrectly";
  1736.     }
  1737.     return 0x10;
  1738.   }
  1739.   if (type==0x01) x= 1.0/0.0;
  1740.   if (type==0x02) f= open("no-such-file-ever-existed");
  1741.   if (type==0x04) return 0x04; /* need user to hit C-c */
  1742.   if (type==0x08) x= 1.0*[];
  1743.   if (type==0x10) error, "---test error, should be caught---";
  1744.   return 0;
  1745. }
  1746.  
  1747. if (!junk(0x01)) "**WARNING** 1.0/0.0 does not trigger SIGFPE";
  1748. if (!junk(0x02)) {
  1749.   goofs++;
  1750.   "**FAILURE** of - catch function - I/O error not caught";
  1751. }
  1752. if (!junk(0x08)) {
  1753.   goofs++;
  1754.   "**FAILURE** of - catch function - compiled error not caught";
  1755. }
  1756. if (!junk(0x10)) {
  1757.   goofs++;
  1758.   "**FAILURE** of - catch function - interpreted error not caught";
  1759. }
  1760.  
  1761. junk= [];
  1762.  
  1763. if (do_stats) "Q "+print(yorick_stats());
  1764.  
  1765. /* ------------------------------------------------------------------------- */
  1766.  
  1767. iS= lS= dS= cA= sA= iA= lA= fA= dA= zA= [];
  1768. write, format= "End of Yorick parser test, %d goofs\n", goofs;
  1769.  
  1770. if (!skip_testb) {
  1771.   require, "testb.i";
  1772.   write,"\n Zeroth test is pdtest files:";  pdcheck2;  write,"";
  1773.   testb;
  1774. }
  1775.  
  1776. if(is_void(npass)) npass= 2;
  1777.  
  1778. /* write if tests twice so that include actually takes place */
  1779. if (!skip_test1) include, "test1.i";
  1780. if (!skip_test1) { write,"\nShock tracker timing test:";  test1, npass; }
  1781.  
  1782. if (!skip_test2) include, "test2.i";
  1783. if (!skip_test2) { write,"\nEscape factor timing test:";  test2, npass; }
  1784.  
  1785.  
  1786. if (!skip_test3) include, "test3.i";
  1787. if (!skip_test3) { write,"\nZone generator timing test:";  test3, npass; }
  1788.